﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTestEx
{
    public static class AssertEx
    {
        public static TException Throws<TException>(Action action)
            where TException : Exception
        {
        	if (action == null)
        	{
        		throw new ArgumentNullException("action");
        	}

        	try
            {
                action.Invoke();
            }
            catch (TException expectedException)
            {
                return expectedException;
            }

            return null;
        }

        public static void DoesNotThrow(Action action)
        {
        	if (action == null)
        	{
        		throw new ArgumentNullException("action");
        	}

        	try
            {
                action.Invoke();
            }
            catch(Exception ex)
            {
                Assert.Fail(action.Method + " threw unexpected exception " + ex.GetType());
            }
        }
    }
}
